package com.jx.db137.service.imp;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jx.db137.entity.Menu;
import com.jx.db137.entity.Rolemenu;
import com.jx.db137.mapper.MenuMapper;
import com.jx.db137.mapper.RolemenuMapper;
import com.jx.db137.service.MenuService;
import com.jx.db137.service.RolemenuService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author jx
 * @version 1.0
 * @Description
 * @date 2024/12/24 11:48
 */
@Service
public class RolemenuServiceImp extends ServiceImpl<RolemenuMapper, Rolemenu> implements RolemenuService {

    @Override
    public boolean updateRoleMenuId(int roleid, List<Integer> listMenu) {
        //1.根据角色id删除这个角色的所有菜单
        UpdateWrapper<Rolemenu> rolemenuUpdateWrapper = new UpdateWrapper<>();
        rolemenuUpdateWrapper.eq("roleid", roleid);
        this.baseMapper.delete(rolemenuUpdateWrapper);
        //2.根据角色id增加对应的菜单
        for (Integer menuid : listMenu) {
            Rolemenu rolemenu = new Rolemenu();
            rolemenu.setRoleid(roleid);
            rolemenu.setMenuid(menuid);
            this.baseMapper.insert(rolemenu);
        }
        return false;
    }


}
